package com.starmark.sys.org.provider.service.impl;




import com.starmark.sys.org.api.dto.OrgElementDto;
import com.starmark.sys.org.api.service.IOrgDepartmentApiService;
import com.starmark.sys.org.provider.constants.OrgApiConstant;
import com.starmark.sys.org.provider.dto.OrgTreeDto;
import com.starmark.sys.org.provider.service.ISysOrgCommonService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

/**
 * @author starmark
 * @version 2018年5月20日 下午3:19:19
 */
@Service

public class OrgDepartmentCommonServiceImpl
        implements ISysOrgCommonService {


    @Autowired
    private IOrgDepartmentApiService orgDepartmentApiService;


    @Override
    public List<OrgTreeDto> getOrgTreeBySearchkey(String searchKey, int pageSize) {
        List<OrgElementDto>  orgDepartmentDtos= orgDepartmentApiService.getOrgTreeBySearchkey(searchKey, pageSize);
        return orgDepartmentDtos.stream().map(orgDepartmentDto -> new OrgTreeDto(orgDepartmentDto, OrgApiConstant.ORG_DEPARTMENT)).collect(Collectors.toList());

    }

    @Override
    public List<OrgTreeDto> getOrgTreeById( String id) {
        List<OrgElementDto>  orgDepartmentDtos= orgDepartmentApiService.getOrgTreeById(id);
        return orgDepartmentDtos.stream().map(orgDepartmentDto -> new OrgTreeDto(orgDepartmentDto, OrgApiConstant.ORG_DEPARTMENT)).collect(Collectors.toList());

    }


    @Override
    public boolean isSearch(int orgType) {
        return (orgType & OrgApiConstant.ORG_DEPARTMENT) == OrgApiConstant.ORG_DEPARTMENT;
    }


    @Override
    public boolean isTree(int orgType) {
        if ((orgType & OrgApiConstant.ORG_DEPARTMENT) == OrgApiConstant.ORG_DEPARTMENT) {
            return true;
        }
        return (orgType & OrgApiConstant.ORG_PERSON) == OrgApiConstant.ORG_PERSON;
    }



}
